"use strict"
/**
 *
 * @param {import("egg").Application} app
 */
module.exports = app => {
	const Sequelize = app.Sequelize
	const sequelize = app.model
	let Application = sequelize.models.application
	let ApplicationUser = sequelize.define("applicationUser", {
		id: {
			primaryKey: true,
			autoIncrement: true,
			type: Sequelize.INTEGER,
		},
		aid: {
			comment: "应用id",//Sequelize.INTEGER
			type: Sequelize.INTEGER,
			references: {
				model: Application
			}
		},
		subscribe: {
			type: Sequelize.TINYINT,
			comment: "1 关注,0 未关注",
		},
		create_at: {
			type: Sequelize.DATE,
			defaultValue: sequelize.literal("CURRENT_TIMESTAMP"),
			get() {
				return Date.parse(this.getDataValue("create_at"))
			},
		},
		last_login: {
			type: Sequelize.DATE,
			defaultValue: sequelize.literal("CURRENT_TIMESTAMP"),
			get() {
				return Date.parse(this.getDataValue("lastLogin"))
			}
		},
		unionid: {
			type: Sequelize.STRING(40),
			comment: "唯一的用户id",
		},
		nickname: Sequelize.STRING(50),
		openid: {
			type: Sequelize.STRING(30),
			comment: "//每个用户都有唯一openid// 当uid 生效时openid 无效",
			unique: true
		},
		stat: {
			type: Sequelize.TINYINT
		},
		language: Sequelize.STRING(10),
		city: Sequelize.STRING(20),
		province: Sequelize.STRING(20),
		country: Sequelize.STRING(20),
		headimg_url: {
			type: Sequelize.STRING,
		},
		subscribe_time: {
			type: Sequelize.DATE,
			comment: "关注时间/取消关注时间"
		},
		remark: Sequelize.STRING,
		groupid: Sequelize.INTEGER,
		tagid_list: Sequelize.STRING(255),
		subscribe_scene: Sequelize.STRING,
		qr_scene: Sequelize.STRING,
		qr_scene_str: Sequelize.STRING,
		sex: {
			type: Sequelize.TINYINT,//
			comment: "性别 0女 1男 "
		},
		ip: {
			type: Sequelize.INTEGER.UNSIGNED
		},
		channel: {
			type: Sequelize.INTEGER,
			defaultValue: 1
		}
	}, {
		tableName: "application_user",
		comment: "针对单一appId和用户关联的表",
		timestamps: false
	})
	ApplicationUser.UserStat = {
		"info": 1,
		"enter": 2,
	}
	return ApplicationUser
}